﻿@model VaccineEbook.Models.CustomPageList<VaccineEbook.Models.DBEntity.PROC_ChapterGroup_Result>
@{
    ViewBag.Title = "Book";
}

<h2>Book</h2>

<!--Edit-->
<form class="form-inline">
    <a href='@Url.Action("Edit", new { })' class="btn btn-primary">Add chapter</a>

    <input type="text" class="form-control" placeholder="Enter text"
           name="@VaccineEbook.Models.Constant.QUICK_SEARCH_STRING"
           value="@Request.QueryString[VaccineEbook.Models.Constant.QUICK_SEARCH_STRING]" />
    <button type="submit" class="btn btn-primary">Search</button>
    @*<button type="button" style="float:right" class="btn btn-danger" onclick="location.href='@Url.Action("Notification", "Chapter")'">
        <span class="glyphicon glyphicon-align-left" aria-hidden="true"></span>
        Push Notification
    </button>*@
    <a class="btn btn-danger pull-right" href='@Url.Action("Notification", "Chapter")'>        
        Push Notification
    </a> 
    @* @Html.ActionLink("Push Notification", "Notification", "Chapter", new { @class = "btn btn-danger pull-right" }) *@
</form>

<!--Display-->
<nav>
    @Html._PageListPager(Request.QueryString, Model, VaccineEbook.Models.Constant.PAGE_LIST_OPTION, null)
</nav>

<table class="table table-bordered table-striped">
    <thead>
        <tr>
            <th>Edit</th>
            <th>Icon</th>
            <th>Group</th>
            <th>Description</th>
            <th>Content</th>            
            <th>Page</th>
            <th style=" text-align:center">Total Pages</th>
        </tr>
    </thead>
    <tbody>
        @if (Model != null)
        {
            if (Model.ListCustom == null)
            {
                <tr><td colspan="100"></td></tr>
            }
            else
            {
                foreach (var item in Model.ListCustom)
                {
                    <tr>
                        <td>
                            <a href='@Url.Action("Edit", new { id=item.ID, ChapterID=item.ChapterID })'>Edit</a>
                            |
                            <a href="#" onclick="Confirm_DeleteChapterGroup(@item.ChapterID)">Delete</a>
                        </td>
                        <td><img src="@item.Icon" style="width: 20px; height: 20px" /></td>
                        <td><span class="chapter-group">@item.ChappterGroup</span></td>
                        @{
                    // loại bỏ 30 kí tự, hay ít hơn trong chapterDesciption, chapterContent
                    string chapterDescription = VaccineEbook.Common.StringHelper.HtmlRemoval.StripTagsCharArray(item.ChapterDescription);
                    string chapterContent = VaccineEbook.Common.StringHelper.HtmlRemoval.StripTagsCharArray(item.ChapterContent);
                    chapterDescription = string.IsNullOrEmpty(chapterDescription) ? "" : chapterDescription.Remove(chapterDescription.Length <= 30 ? chapterDescription.Length - 1 : 30);
                    chapterContent = string.IsNullOrEmpty(chapterContent) ? "" : chapterContent.Remove(chapterContent.Length <= 30 ? chapterContent.Length - 1 : 30);
                        }
                        <td><span class="cut-inline">@chapterDescription</span> ...</td>
                        <td><span class="cut-inline">@chapterContent</span> ...</td>
                        
                        <td>@item.Page</td>
                        <td>@item.TotalPage</td>
                    </tr>
                }
            }
        }
    </tbody>
</table>

<nav>
    @Html._PageListPager(Request.QueryString, Model, VaccineEbook.Models.Constant.PAGE_LIST_OPTION, null)
</nav>

<!--Edit model-->
<div class="modal fade" id="edit-vaccine-modal">
    <div id="edit-vaccine-container"></div>
</div>

@section style{
    <style>
        .chapter-group {
            font-weight: bold;
        }

        .cut-inline {
        }
    </style>
}

@section script{
    <script type="text/javascript">

        // detete confirm
        function Confirm_DeleteChapterGroup(chapterGroupId) {
            if (confirm("Delete this group?")) {
                var url = '@Url.Action("DeleteChapterGroup", "Chapter")';
                url += "?ChapterGroupID=" + chapterGroupId;
                location.href = url;
            }
        }

    </script>
}
